﻿<phone:PhoneApplicationPage 
    x:Class="DDU.Curriculum.Views.BookEditView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:UX="clr-namespace:DDU.UX;assembly=DDU.UX"
    xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
    xmlns:Converters="clr-namespace:DDU.Converters;assembly=DDU.Converters"
    xmlns:viewmodel="clr-namespace:DDU.ViewModel;assembly=DDU.ViewModel"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    mc:Ignorable="d" d:DesignHeight="800" d:DesignWidth="480"
    shell:SystemTray.IsVisible="False">

    <phone:PhoneApplicationPage.Resources>
        <Converters:EnumTranslateConverter x:Key="EnumTranslateConverter"/>
        <Converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
        <Converters:StreamToImageConverter x:Key="StreamToImageConverter" />
        <Converters:StringToPathGeometryConverter x:Key="StringToPathGeometryConverter" />
    </phone:PhoneApplicationPage.Resources>

    <Grid x:Name="LayoutRoot">
        <Grid.Background>
            <ImageBrush ImageSource="/Assets/back.png"/>
        </Grid.Background>
        <Grid.DataContext>
            <viewmodel:BookEditViewModel/>
        </Grid.DataContext>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
            <TextBlock Text="{StaticResource IDS_APP_NAME}" Style="{StaticResource PhoneTextNormalStyle}"/>
            <TextBlock Text="添加课本" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
        </StackPanel>

        <!--ContentPanel - place additional content here-->
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0" Visibility="{Binding Path=ContentPanelVisibility}">
            <Grid.RowDefinitions>
                <RowDefinition/>
                <RowDefinition Height="auto"/>
            </Grid.RowDefinitions>
            <ScrollViewer>
                <StackPanel>
                    <toolkit:ListPicker ItemsSource="{Binding ItemsOfSemesters}" SelectedItem="{Binding SelectedSemester,Mode=TwoWay}" ExpansionMode="FullScreenOnly">
                        <toolkit:ListPicker.ItemTemplate>
                            <DataTemplate>
                                <TextBlock >
                                    <Run Text="{Binding EducationLevel, Converter={StaticResource EnumTranslateConverter}}"/>
                                    <Run Text=" "/>
                                    <Run Text="{Binding Grade, Converter={StaticResource EnumTranslateConverter}}"/>
                                    <Run Text=" "/>
                                    <Run Text="{Binding Term, Converter={StaticResource EnumTranslateConverter}}"/>
                                </TextBlock>
                            </DataTemplate>
                        </toolkit:ListPicker.ItemTemplate>
                        <toolkit:ListPicker.FullModeItemTemplate>
                            <DataTemplate>
                                <TextBlock Style="{StaticResource PhoneTextTitle2Style}" Margin="0,12">
                                    <Run Text="{Binding EducationLevel, Converter={StaticResource EnumTranslateConverter}}"/>
                                    <Run Text=" "/>
                                    <Run Text="{Binding Grade, Converter={StaticResource EnumTranslateConverter}}"/>
                                    <Run Text=" "/>
                                    <Run Text="{Binding Term, Converter={StaticResource EnumTranslateConverter}}"/>
                                </TextBlock>
                            </DataTemplate>
                        </toolkit:ListPicker.FullModeItemTemplate>
                    </toolkit:ListPicker>

                    <TextBlock Style="{StaticResource PhoneTextSubtleStyle}" Text="课本名称"/>
                    <TextBox Text="{Binding Path=BookToEdit.Title, Mode=TwoWay}" />
                    <TextBlock Style="{StaticResource PhoneTextSubtleStyle}" Text="任课老师"/>
                    <TextBox Text="{Binding Path=BookToEdit.Teahcer, Mode=TwoWay}" />
                    <TextBlock Style="{StaticResource PhoneTextSubtleStyle}" Text="出版社"/>
                    <TextBox Text="{Binding Path=BookToEdit.Press, Mode=TwoWay}" />
                    <TextBlock Style="{StaticResource PhoneTextSubtleStyle}" Text="定价"/>
                    <TextBox Text="{Binding Path=BookToEdit.Price, Mode=TwoWay}" InputScope="Number"/>
                    <TextBlock Style="{StaticResource PhoneTextSubtleStyle}" Text="出版编号(ISBN)"/>
                    <TextBox Text="{Binding Path=BookToEdit.ISBN, Mode=TwoWay}" />
                </StackPanel>
            </ScrollViewer>

            <Grid Grid.Row="1" Margin="0,12">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition/>
                    <ColumnDefinition Width="auto"/>
                </Grid.ColumnDefinitions>

                <Grid Width="180" Height="180" HorizontalAlignment="Left" Margin="12,0" Background="{StaticResource PhoneSubtleBrush}">
                    <Path Margin="20" Stretch="Uniform" Data="{Binding Source={StaticResource PATH_ICON_BOOK}, Converter={StaticResource StringToPathGeometryConverter}}" Fill="{StaticResource PhoneChromeBrush}"/>
                </Grid>
                <Image Width="180" Height="180" Stretch="Fill" HorizontalAlignment="Left" Margin="12,0" Source="{Binding Converter={StaticResource StreamToImageConverter}, Path=BookToEdit.Stream}" />
                
                <UX:CircularPanel AngleItem="60" Radius="68" AnimationDuration="1" Grid.Column="1" Align="Center" IsAnimated="True" >
                    <UX:UXPathButton IconPath="{StaticResource PATH_ICON_DELETE}" Command="{Binding DeleteCommand}"/>
                    <UX:UXPathButton IconPath="{StaticResource PATH_ICON_CLOSE}" Command="{Binding CancelCommand}" Padding="13"/>
                    <UX:UXPathButton IconPath="{StaticResource PATH_ICON_PICFOLDER}" Command="{Binding OpenGalleryCommand}" />
                    <UX:UXPathButton IconPath="{StaticResource PATH_ICON_BARCODE}" Command="{Binding BarcodeCommand}" />
                    <UX:UXPathButton IconPath="{StaticResource PATH_ICON_CAMERA}" Command="{Binding CameraCommand}" />
                    <UX:UXPathButton IconPath="{StaticResource PATH_ICON_VIEWMEDIUM}" Command="{Binding ChooseCommand}" />

                </UX:CircularPanel>

                <UX:UXPathButton IconPath="{StaticResource PATH_ICON_SUBMIT}" Command="{Binding UpdateCommand, Mode=OneWay}" Grid.Column="2"/>
            </Grid>

        </Grid>

        <Grid Grid.Row="1" Margin="0,12" Visibility="{Binding Path=GalleryPanelVisibility}">
            <Grid.RowDefinitions>
                <RowDefinition/>
                <RowDefinition Height="auto"/>
            </Grid.RowDefinitions>
            <ListBox ItemsSource="{Binding Path=StoredCoverImages}" SelectedItem="{Binding Path=SelectedCover, Mode=TwoWay}">
                <ListBox.ItemsPanel>
                    <ItemsPanelTemplate>
                        <toolkit:WrapPanel></toolkit:WrapPanel>
                    </ItemsPanelTemplate>
                </ListBox.ItemsPanel>
                <ListBox.ItemContainerStyle>
                    <Style TargetType="ListBoxItem">
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="ListBoxItem">
                                    <Grid Margin="12,0,0,12">
                                        <Image Width="210" Height="210" 
                                                       Source="{Binding Stream, Converter={StaticResource StreamToImageConverter}}" Stretch="Fill" />
                                        <Border BorderThickness="4" 
                                                        BorderBrush="{StaticResource PhoneForegroundBrush}" 
                                                        Visibility="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=IsSelected, Converter={StaticResource BooleanToVisibilityConverter}}">
                                            <Path Data="M51.790001,24.177999L44.657009,31.310526 42.412151,33.555641 42.360149,33.608337 40.141289,31.392622 33.010998,24.259096 33.010998,30.443459 39.294868,36.728317 42.38615,39.820999 45.479931,36.728317 45.45393,36.701019 45.505932,36.64822 51.790001,30.363361z M42.398598,16.777C50.804901,16.777 57.619999,23.591635 57.619999,32 57.619999,40.406467 50.804901,47.223 42.398598,47.223 33.9897,47.223 27.174,40.406467 27.174,32 27.174,23.591635 33.9897,16.777 42.398598,16.777z M0,0L31.899,0C40.984901,0.20117199,42.398998,8.6806602,42.398998,8.6806602L42.398998,13.110001 41.91222,13.116181C31.719772,13.375278 23.508001,21.74651 23.508001,31.99995 23.508001,42.252407 31.719772,50.623718 41.91222,50.88282L42.398998,50.889 42.398998,64 25.8801,47.848598 9.2863798,64 9.2863798,8.6806602C8.2785301,1.00879,0,0,0,0z" 
                                                          Stretch="Uniform" Fill="{StaticResource PhoneForegroundBrush}" Width="36" Height="36" VerticalAlignment="Top" HorizontalAlignment="Right" Margin="0,0,0,0" RenderTransformOrigin="0.5,0.5">
                                                <Path.RenderTransform>
                                                    <TransformGroup>
                                                        <TransformGroup.Children>
                                                            <RotateTransform Angle="0" />
                                                            <ScaleTransform ScaleX="1" ScaleY="1" />
                                                        </TransformGroup.Children>
                                                    </TransformGroup>
                                                </Path.RenderTransform>
                                            </Path>
                                        </Border>
                                    </Grid>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </ListBox.ItemContainerStyle>
            </ListBox>

            <Grid Grid.Row="1" Margin="12">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition/>
                    <ColumnDefinition Width="auto"/>
                    <ColumnDefinition/>
                </Grid.ColumnDefinitions>
                <Rectangle Height="1" Margin="12,0" Fill="{StaticResource PhoneForegroundBrush}"/>
                <Rectangle Height="1" Margin="12,0" Fill="{StaticResource PhoneForegroundBrush}" Grid.Column="2"/>

                <StackPanel Orientation="Horizontal" Grid.Column="1">
                    <UX:UXPathButton IconPath="{StaticResource PATH_ICON_CHECK}" Command="{Binding SelectedOKCommand}" />
                    <Rectangle Width="12"/>
                    <UX:UXPathButton IconPath="{StaticResource PATH_ICON_CLOSE}" Command="{Binding HideGalleryCommand}" Padding="14" />
                </StackPanel>
            </Grid>
        </Grid>
    </Grid>

    <!--Sample code showing usage of ApplicationBar-->
    <!--<phone:PhoneApplicationPage.ApplicationBar>
        <shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">
            <shell:ApplicationBarIconButton IconUri="/Images/appbar_button1.png" Text="Button 1"/>
            <shell:ApplicationBarIconButton IconUri="/Images/appbar_button2.png" Text="Button 2"/>
            <shell:ApplicationBar.MenuItems>
                <shell:ApplicationBarMenuItem Text="MenuItem 1"/>
                <shell:ApplicationBarMenuItem Text="MenuItem 2"/>
            </shell:ApplicationBar.MenuItems>
        </shell:ApplicationBar>
    </phone:PhoneApplicationPage.ApplicationBar>-->

</phone:PhoneApplicationPage>
